<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <meta name="renderer" content="webkit">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <link rel="stylesheet" href="../../css/style.css">
     <link rel="stylesheet" href="../../css/order.css">
    <title>交易订单</title>
    <style>
    </style>
</head>
<body>

    <div class="configNav"></div>
    <!-- content -->
    <div class="container-fluid">
        <div class="row">
            <!-- left -->
            <div class="col-md-2">
                <div class="list-group">
                    <a href="order_index.html" class="list-group-item active">交易订单</a>
                    <a href="deliver_index.html" class="list-group-item ">发货</a>
                    <a href="address.html" class="list-group-item ">发货设置</a>
                    <a href="evaluate_admin.html" class="list-group-item ">评价管理</a>
                </div>
            </div>
            <!-- right -->
            <div class="col-md-10">
                <ol class="breadcrumb">
                    <li><a href="">商家管理中心</a></li>
                    <li><a href="">订单物流</a></li>
                    <li class="active"><a href="">交易订单</a></li>
                </ol>
                <ul class="nav nav-tabs">
                    <li class="chose"><a href="order_index.html">所有订单</a></li>
                    <li><a href="order_waitPay.html">待付款</a></li>
                    <li><a href="order_waitSend.html">待发货</a></li>
                    <li><a href="order_alreadySend.html">已发货</a></li>
                    <li><a href="order_success.html">已完成</a></li>
                    <li><a href="order_cancel.html">已取消</a></li>
                </ul>
                <div id="search">
                    <form class="form-inline col-md-10">
                        <div class="form-group">
                            <label>
	                            <input type="checkbox" name="noShow" id="noShow">不显示已关闭的订单
	                        </label>
                            <label for="">下单时间</label>
                            <div class="input-group date form_date_str" id="startTime" data-date="" data-date-format="dd MM yyyy" data-link-format="yyyy-mm-dd">
                                <input class="sreenMedia" type="text" value="" readonly>
                                <span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
                            </div>
                            -
                            <div class="input-group date  form_date_end" id="endTime" data-date="" data-date-format="dd MM yyyy" data-link-format="yyyy-mm-dd">
                                <input class="sreenMedia" type="text" value="" readonly>
                                <span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
                            </div>
                            <label>买家
                            <input class="sreenMedia" type="text" id="searchBuyerName">
                            </label>
                            <label>订单编号
                            <input class="sreenMedia" type="text" id="searchOrderSn">
                            </label> 支付方式
                            <select id="paymentCode">
                                    <option value="">全部</option>
                                    <option value="1">支付宝支付</option>
                                    <option value="2">金券支付</option>
                                    <option value="3">物券支付</option>
                                    <option value="4">银行卡支付</option>
                                    <option value="5">微信支付</option>
                            </select>
                        </div>
                    </form>
                    <button style="width:70px;" class="searchBtn">搜索</button>
                </div>
                <!--<div class="nav nav-tabs">
                    <a class="btn btn-primary active allorder" href="javascript:;" role="button"><i class="glyphicon glyphicon-search"></i>全部订单</a>
                     <a class="btn btn-primary" href="javascript:;" role="button"><i class="glyphicon glyphicon-search"></i>普通用户订单</a>
                    <a class="btn btn-primary" href="javascript:;" role="button"><i class="glyphicon glyphicon-search"></i>企业用户订单</a> 
                </div>-->
                <table class="table table-bordered">
                    <thead>
                        <tr class="order-ti">
                            <th class="col-md-3">商品</th>
                            <th >单价</th>
                            <th >数量</th>
                            <th >买家</th>
                            <th class="col-md-2">订单金额</th>
                            <th class="col-md-2">交易状态</th>
                            <th class="col-md-2">交易操作</th>
                        </tr>
                    </thead>
                    <tbody id="orderList">
                    </tbody>
                </table>
            
                <nav aria-label="...">
                    <div class="">
                        <span id="pageNum">共&nbsp;<strong></strong>&nbsp;页&nbsp;/&nbsp;</span><span id="totalNum">&nbsp;<strong>0</strong>&nbsp;条数据</span>
                    </div>
                    <ul id="example"></ul>
                </nav>
                </div>
            </div>
        </div>
    <script src="../../js/jquery.min.js" charset="utf-8"></script>
    <script src="../../js/bootstrap.min.js" charset="utf-8"></script>
    <script src="../../plugin/layer/layer.js" charset="utf-8"></script>
    <script src="../../plugin/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js" charset="utf-8"></script>
    <script src="../../plugin/bootstrap-datetimepicker/js/bootstrap-datetimepicker.zh-CN.js" charset="utf-8"></script>
    <script src="../../plugin/wangEditor/release/wangEditor.min.js" charset="utf-8"></script>
    <script src="../../js/nav.js" charset="utf-8"></script>
    <script src="../../js/common.js" charset="utf-8"></script>
    <script src="../../js/bootstrap-paginator.js" charset="utf-8"></script>
    <script src="../../js/ajax.js" charset="utf-8"></script>
    <script type="text/javascript">
        //时间
	        $(".form_date_str").datetimepicker({
	    　    minView: "month", 
	        　format: "yyyy-mm-dd", 
	        　language: 'zh-CN', 
	        　autoclose:true 
	        });
	        $(".form_date_end").datetimepicker({
	        　minView: "month", 
	        　format: "yyyy-mm-dd", 
	        　language: 'zh-CN',
	        　autoclose:true 
	        });

        $(document).ready(function() {
            tableList()
        });
        //查询商家订单列表
        var pageUrls = cncbk_common_tools.serverURL + '/business/order/queryOrderList';
        function tableList() {

            //分页
            data = {
                'page': page,
                'pageSize': pagesize
            }
            data.page = 1
            ajax(
                pageUrls,
                data,
                pageNumList,
                'post',
                'json'
            )
        }
        //不显示已取消的订单
        $('#noShow').off('click').click(function() {
            if ($(this).is(':checked')) {
                $('.noShow').hide()
            } else {
                $('.noShow').show()
            }
        })
//      //全部订单
//      $('.allorder').off('.click').on('click', function() {
//          if ($('#noShow').is(':checked')) {
//              $('#noShow').click();
//          }
//          tableList()
//      })
        //数据渲染
        function OpendList(res) {
            $('#orderList').empty();
            var html = '';
            for (var i = 0; i < res.data.list.length; i++) {
                var noShow = '',goodsPriceUnit='';
                if (Number(res.data.list[i].orderStatus) == 7) {
                    noShow = 'noShow';
                }
                var orderDetailId = res.data.list[i].orderDetailId;
                var goodsPrice = res.data.list[i].goodsPrice;
                var isSpe = res.data.list[i].isSpe;
                	var nuit='';
                	if (isSpe == 1){
                		nuit='券';
                		goodsPriceUnit='<span>' + goodsPrice + nuit + '</span>';
                	}if (isSpe ==0) {
                		nuit='元';
                		goodsPriceUnit='<span>' + goodsPrice + nuit + '</span>';
                	}
                html += '<tr class="' + noShow + '">' +
                    '<th colspan="7" class="thli">' +
                    '<ul>' +
                    '<li class="orderDetailId" orderDetailId="' + orderDetailId + '">订单编号：<span>' + res.data.list[i].orderSn + '</span><span><i class="glyphicon glyphicon-phone"></i></span></li>' +
                    '<li>下单时间：<span>' + res.data.list[i].orderTime + '</span></li>' +
                    '<li style="float:right;">' +
                    '<button type="submit" class="orderPrint" orderDetailId="' + orderDetailId + '" style="margin:5px;"><i class="glyphicon glyphicon-print"></i>打印发货单</button>' +
                    '</li>' +
                    '</ul>' +
                    '</th>' +
                    '</tr>' +
                    '<tr class="' + noShow + '">' +
                    '<td class="thli col-md-3">' +
                    '<ul class="goods">' +
                    '<li class="goodsimg"><img src="http://axyhpic.oss-cn-zhangjiakou.aliyuncs.com/' + res.data.list[i].goodsImage + '" alt=""></li>' +
                    '<li class="goodsName"><a href="http://47.92.118.122/html/wytx/goods_particulars.html?id='+res.data.list[i].goodsId +'">' + res.data.list[i].goodsName + '</a></li>' +
                    '</ul>' +
                    '</td>' +
                    '<td style="vertical-align:middle;"><span>' + goodsPriceUnit + '</span></td>' +
                    '<td style="vertical-align:middle;"><span>' + res.data.list[i].goodsQuantity + '</span></td>' +
                    '<td style="vertical-align:middle;" class="memberInfo" orderDetailId="' + res.data.list[i].orderDetailId + '">' + res.data.list[i].memberName +
                    '<div class="suspendMain suspendMain' + res.data.list[i].orderDetailId + '">' +
                    '</div>' +
                    '</td>' +
                    '<td >' +
                    '<ul>' +
                    '<li style="color:#f00;"><span>' + res.data.list[i].orderAmount + '</span>元</li>' +
                    '<li style="color:#f00;"><span orderDetailId="' + res.data.list[i].orderDetailId + '" class="isSpe">' + res.data.list[i].isSpe + '</span>券</li>' +
                    '<li><span class="goodsFreight">运费：￥' + res.data.list[i].goodsFreight + '元</span></li>' +
                    '<li><span>' + res.data.list[i].paymentCode+ '</span></li>' +
                    '</ul>' +
                    '</td>' +
                    '<td>' +
                    '<span class="orderStatus">' + res.data.list[i].orderStatus + '</span><br>' +
                    '<span ><a href="order_detail.html?orderDetailId=' + orderDetailId + '"  class="orderDteails">订单详情</a></span>' +
                    '</td>' +
                    '<td>'
                   if(res.data.list[i].orderStatus == 1){
                   	html +='<button class="btn btn-danger removeOrder" orderStatus="' + res.data.list[i].orderStatus + '" data-toggle="modal" data-target="#removeorder'+orderDetailId+'" orderDetailId="'+orderDetailId+'"><i class="glyphicon glyphicon-remove" ></i>取消订单</button>'
                   }
//                 else{
//                 	html += '<button class="btn btn-danger removeOrder" style="display:none;" orderStatus="' + res.data.list[i].orderStatus + '" data-toggle="modal" data-target="#removeorder'+orderDetailId+'" orderDetailId="'+orderDetailId+'"><i class="glyphicon glyphicon-remove" ></i>取消订单</button>'+
//                 }
	                html += '<div class="modal fade" id="removeorder'+orderDetailId+'" aria-labelledby="modaladdress" aria-hiddden="true">'+
	                '<div class="modal-dialog">'+
	                '<div class="modal-conent">'+
	                    '<div class="modal-header">'+
	                        '<button type="button" class="close myClose" data-dismiss="modal" aria-hidden="true">X</button>'+
	                        '<h4 class="modal-title" id="modaladdress">取消订单</h4>'+
	                    '</div>'+
	                    '<div class="modal-body">'+
	                        '<form role="form">'+
	                        '<div class="form-group">'+
	                        '<div class="reason">订单编号：<span>'+res.data.list[i].orderSn+'</span></div>'+
	                        '</div>'+
	                        '<div class="form-group reason">'+
	                        '<label for="area">取消缘由：</label>'+
	                        '<ul>'+
	                        '<li><input type="radio" name="reason" value="1">无法备齐的货物<li>'+
	                        '<li><input type="radio"  name="reason" value="2">不是有效的订单<li>'+
	                        '<li><input type="radio"  name="reason" value="3">应买家主动要求<li>'+
	                        '<li><input type="radio"  id="other" name="reason" value="4">其他的取消原因<li>'+
	                        '<li ><textarea id="otherReasonDesc"  col="20" rows="3"   name="reason"  ></textarea><li>'+
	                        '</ul>'+
	                        '</div>'+
	                        '</form>'+
	                    '</div>'+
	                    '<div class="modal-footer">'+
	                        '<div>'+
	                        '<button class="yesCancel" type="button" class="btn- btn-success">保存</button>'+
	                        '</div>'+
	                     '</div>'+
	                '</div>'+
	                '</div>'+
	                '</div>'+
                    '<br>' +
                    '<button class="btn-revise deliverJump" style="display:none;" orderStatus="' + res.data.list[i].orderStatus + '" orderDetailId="' + res.data.list[i].orderDetailId + '" > <i class="glyphicon glyphicon-plane"></i>设置发货</button>' +
                    '</td>' +
                    '</tr>';
            }

            $('#orderList').append(html);
//          $.each($('.memberInfo'), function(i, j) {
//              var orderDetailId = $(this).attr('orderDetailId'); //订单明细id
//              $('.suspendMain' + orderDetailId).hide();
//              var pageUrls = cncbk_common_tools.serverURL + '/business/order/orderDetail';
//              data = {
//                  'orderDetailId': orderDetailId,
//              }
//              var func = function(res) {
//                  var html = '';
//                  html +=
//                      '<div class="suapend">' +
//                      '<div class="suspendContent">' +
//                      '<h5>联系信息</h5>' +
//                      '<ul>' +
//                      '<li><span>姓名：' + res.data.orderReciver.name + '</span></li>' +
//                      '<li><span>电话：' + res.data.orderReciver.phone + '</span></li>' +
//                      '<li><span>地址：' + res.data.orderReciver.addressName + res.data.orderReciver.address + '</span></li>' +
//                      '</ul>' +
//                      '</div>' +
//                      '</div>';
//                  $('.suspendMain' + orderDetailId).append(html);
//              }
//              ajax(
//                  pageUrls,
//                  data,
//                  func,
//                  'post',
//                  'json'
//              )
//          })
            //订单状态显示
            $.each($('.orderStatus'), function() {
                switch (Number($(this).text())) {
                    case 1:
                        $(this).text('待付款');
                        break;
                    case 2:
                        $(this).text('待发货');
                        break;
                    case 3:
                        $(this).text('已发货');
                        break;
                    case 4:
                        $(this).text('已收货');
                        break;
                    case 5:
                        $(this).text('待评价');
                        break;
                    case 6:
                        $(this).text('已评价');
                        break;
                    case 7:
                        $(this).text('已取消');
                        break;
                    case 8:
                        $(this).text('退款');
                        break;
                    case 9:
                        $(this).text('拒收');
                        break;
                    case 10:
                        $(this).text('延迟收货');
                        break;
                }
            })
        
            //显示取消订单按钮
//          $.each($('.removeOrder'), function() {
//              if ($(this).attr('orderStatus')  == 1 ) {
//                  $(this).show();
//              }
//          })
            //显示发货设置按钮
            $.each($('.deliverJump'), function() {
                if ($(this).attr('orderStatus') == 2) {
                    $(this).show()
                }
            })
     		
//   		  	//其他原因
//	            $('#other').off('click').click(function(){
//	            	console.log(11)
//	                $('#otherReasonDesc').show();
//	            })
            //取消订单
            $('.removeOrder').click(function(){
                //获取订单明细id、取消原因id
                var pageUrls =cncbk_common_tools.serverURL +'/business/order/queryOrderList';
                var orderDetailId = $(this).attr('orderDetailId');
                data ={
                    'orderDetailId':orderDetailId,
                    // 'cancelReason':cancelReason
                }
                var func = function (res){
                    console.log(res)
                }
                ajax(
                    pageUrls,
                    data,
                    func,
                    'post',
                    'json'
                )
                 
            })
            //点击保存确定取消订单
            $('.yesCancel').click(function(){
            	console.log(111111)
                var pageUrls =serverURL +'/order/updateCalcelOrder';
                var orderDetailId = $('.orderDetailId').attr('orderDetailId');//获得订单id
                var cancelReason = $('input[name="reason"]').val();
                var otherReasonDesc = $('#otherReasonDesc').val();
                var data ={
                    'orderDetailId':orderDetailId,
                    'cancelReason':cancelReason,
                    'otherReasonDesc':otherReasonDesc
                }
                var funcOr = function (res){
                	if(res.code == '200'){
//              		$('.modal').modal('hide');
						$('div').removeClass('modal-backdrop');
                		tableList();
                	} 
                }
                ajax(
                    pageUrls,
                    data,
                    funcOr,
                    'post',
                    'json'
                )
            })

            //搜索
            $('.searchBtn').click(function() {

                var pageUrls = cncbk_common_tools.serverURL + '/business/order/queryOrderList';
                var startTime = $('#startTime').val();
                var endTime = $('#endTime').val();
                var buyerName = $('#searchBuyerName').val();
                var orderSn = $('#searchOrderSn').val();
                var paymentCode = $('#paymentCode').val();
                console.log(paymentCode)
                data = {
                    'startTime': startTime,
                    'endTime': endTime,
                    'buyerName': buyerName,
                    'orderSn': orderSn,
                    'paymentCode': paymentCode,
                    'page': 1,
                    'pageSize': 10
                }
                ajax(
                    pageUrls,
                    data,
                    pageNumList,
                    'post',
                    'json'
                )
            })

//
//          // 买家信息
//          $('.memberInfo').mouseenter(function() {
//              var orderDetailId = $(this).attr('orderDetailId'); //订单明细id
//              $('.suspendMain' + orderDetailId).show();
//          }).mouseleave(function() {
//              var orderDetailId = $(this).attr('orderDetailId'); //订单明细id
//              $('.suspendMain' + orderDetailId).hide();
//          })
            //设置发货跳转
            $('.deliverJump').click(function() {
                window.location.href = "deliver_set.html?orderDetailId=" + $(this).attr('orderDetailId');
            })
            //打印发货单跳转
            $('.orderPrint').click(function() {
                window.location.href = "order_print.html?orderDetailId=" + $(this).attr('orderDetailId');
            })

        }
    </script>
</body>

</html>
